import {ExcelColumnData} from "./ExcelColumnData";
import {Utils} from "../Utils";

class ExcelTypeChecker
{
	public CheckType(){
	}

	public ParseValue(val, member_type, columnData : ExcelColumnData, cell ){
		try {
			var func = this["parse" + member_type](val, columnData)
			func(val, columnData)
		}catch (e) {
			// Utils.columnRaiseError(columnData, 'parse_value is error', cell)
		}
	}

	int_str_checker = /^(\d*)|(-\d*)$/

	// 解析
	parseInt(value, error_func)
	{
		if(value == null){
			return
		}
		if(typeof value == "string"){
			var math_ret = value.match(this.int_str_checker)
			if (math_ret == undefined)
			{
				error_func(`need value is int, but get: ${value}`)
			}
		}
		return Number(value)
	}

	parseString(value, error_func, index=0)
	{
		if(value == undefined){
			return
		}
		return value
	}

	float_str_checker = /^(\d*|\d*.\d*|-\d*.\d*)$/
	parseFloat(value, error_func, index = 0)
	{
		if(value == undefined){
			return
		}
		if(typeof value == "string"){
			var math_ret = value.match(this.float_str_checker)
			if(math_ret == undefined){
				error_func(`"need value is float, but get: ${value}`)
			}
		}
		var ret = Number(value)
		return ret
	}

}

export default new ExcelTypeChecker()
